package com.first.group.gateway.config;

import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author 小刘的小张
 * @version 1.0
 * @description: TODO
 * @date 2021/10/24 22:49
 */
@Configuration
public class FreeSentinelConfig {


    public FreeSentinelConfig() {
        GatewayCallbackManager.setBlockHandler(new BlockRequestHandler() {
            //网关限流后，调动此方法
            @Override
            public Mono<ServerResponse> handleRequest(ServerWebExchange serverWebExchange, Throwable throwable) {

                return ServerResponse.ok().body(Mono.just("网络出问题了"), String.class);
            }
        });
    }


}
